#ifndef OCCOBJECTBASE_H
#define OCCOBJECTBASE_H

#include <QObject>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Solid.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
#include <gp_Trsf.hxx>
#include <TopoDS.hxx>
#include <ShapeFix_ShapeTolerance.hxx>

Q_DECLARE_METATYPE(TopoDS_Shape)
Q_DECLARE_METATYPE(TopoDS_Edge)
Q_DECLARE_METATYPE(gp_Trsf)
Q_DECLARE_METATYPE(TopoDS_Face)
Q_DECLARE_METATYPE(TopoDS_Shell)
Q_DECLARE_METATYPE(TopoDS_Solid)
Q_DECLARE_METATYPE(TopoDS_Wire)
Q_DECLARE_METATYPE(gp_Pnt)
Q_DECLARE_METATYPE(gp_Vec)
Q_DECLARE_METATYPE(QVector<TopoDS_Edge>)
Q_DECLARE_METATYPE(QVector<QVariant>)
Q_DECLARE_METATYPE(QVector<int>)
class OccObjectBase : public QObject
{
	Q_OBJECT

public:
	OccObjectBase(QObject *parent);
	~OccObjectBase();
protected:
	template<class T>
	QVariant ToVariant(const T& shape)
	{
		QVariant var;
		var.setValue(shape);
		return var;
	}
	QVariant ShapeToVariant(const TopoDS_Shape& shape)
	{
		ShapeFix_ShapeTolerance tol;
		tol.SetTolerance(shape, 0.01, TopAbs_VERTEX);
		QVariant var;
		var.setValue(shape);
		return var;
	}
	void SetShapeTol(const TopoDS_Shape& shape)
	{
		ShapeFix_ShapeTolerance tol;
		tol.SetTolerance(shape, 0.01, TopAbs_VERTEX);
	}
	
	template<class T>
	QVariant ToVariant(const ZMVector<T>& vData)
	{
		QList<QVariant> lsData;
		for (const T &data:vData)
		{
			lsData.append(ToVariant(data));
		}
		QVariant var;
		var.setValue(lsData);
		return var;
	}
	ZMVector<TopoDS_Wire> ChangeToWire(const ZMVector<TopoDS_Shape>& vData)
	{
		ZMVector<TopoDS_Wire> ret(vData.size());
		int i = 0;
		for (const TopoDS_Shape& data : vData)
		{
			ret[i] = TopoDS::Wire(data);
			++i;
		}
		return ret;
	}

	ZMVector<TopoDS_Edge> ChangeToEdge(const ZMVector<TopoDS_Shape>& vData)
	{
		ZMVector<TopoDS_Edge> ret(vData.size());
		int i = 0;
		for (const TopoDS_Shape& data : vData)
		{
			ret[i] = TopoDS::Edge(data);
			++i;
		}
		return ret;
	}

	ZMVector<TopoDS_Face> ChangeToFace(const ZMVector<TopoDS_Shape>& vData)
	{
		ZMVector<TopoDS_Face> ret(vData.size());
		int i = 0;
		for (const TopoDS_Shape& data : vData)
		{
			ret[i] = TopoDS::Face(data);
			++i;
		}
	}
	template<class T>
	ZMVector<T> FromVariant(const QVariant& data)
	{
		QList<QVariant> lsData = data.toList();
		if (lsData.empty())
		{
			lsData.push_back(data);
		}
		ZMVector<T> ret(lsData.size());
		int i = 0;
		for (const QVariant& data:lsData)
		{
			ret[i] = data.value<T>();
			++i;
		}
		return ret;
	}
private:
	
};

#endif // OCCOBJECTBASE_H
